//
//  DrowViewController.m
//  Leisure
//
//  Created by xalo on 16/6/28.
//  Copyright © 2016年 Eason. All rights reserved.
//

#import "DrowViewController.h"

@interface DrowViewController ()<MenuViewControllerDelegate>
/**  接收菜单栏 */
@property (nonatomic,strong)MenuViewController *menuVC;

/** 右侧视图导航栏 */
@property (nonatomic,strong)UINavigationController *rightNVC;


@end

@implementation DrowViewController
//自定义初始化方法，在初始化的时候，就直接给上左右控制器
- (instancetype)initWithMenuViewController:(MenuViewController *)menuVC rightViewCrotroller:(RightViewController *)rightVC
{
    self = [super init];
    if (self) {
        self.menuVC = menuVC;
        self.rightNVC = [[UINavigationController alloc]initWithRootViewController:rightVC];
        self.menuVC.delegate = self;
    }
    return self;
}




- (void)viewDidLoad {
    [super viewDidLoad];

//    添加子视图控制器
    [self addChildViewController:self.menuVC];
//    添加子视图
    [self.view addSubview:self.menuVC.view];
    [self.view addSubview:self.rightNVC.view];
    
    
}

//实现协议方法,更换右视图
-(void)menuViewControllerDelegateDidClickCellWithVC:(RightViewController *)VC{
//    移除之前先把旧的向右偏移
    [UIView animateWithDuration:0.2 animations:^{
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);

    }completion:^(BOOL finished) {
//            先移除旧的
            [self.rightNVC removeFromParentViewController];
            [self.rightNVC.view removeFromSuperview];
        
        
            self.rightNVC = [[UINavigationController alloc]initWithRootViewController:VC];
        //    再添加新的
            [self addChildViewController:self.rightNVC];
            [self.view addSubview:self.rightNVC.view];
        
        self.rightNVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
        
//        把新的再偏移回来
        [UIView animateWithDuration:0.2 delay:0.3 options:UIViewAnimationOptionLayoutSubviews animations:^{
            self.rightNVC.view.frame = self.view.frame;
            
        } completion:^(BOOL finished) {
            
        }];
        
    }];
    

    
}











@end
